package com.rsg.component;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;

public class MakeChain<T extends JComponent>{
	T component=null;
	public MakeChain(T component){
		this.component= component;
	}
	public MakeChain(){
		;
	}
	public MakeChain<T> make(T component){
		this.component=component;
		return this;
	}
	//支持链式构建的属性设置
	public MakeChain<T> setSizex(int w, int h){
		component.setSize(w,h);
		return this;
	}
	public MakeChain<T> setLocationx(int x, int y){
		component.setLocation(x,y);
		return this;
	}
	public MakeChain<T> setBoundsx(int x, int y, int width, int height){
		component.setBounds(x,y,width,height);
		return this;
	}
	public MakeChain<T> setBoundsx(int x, int y, Dimension d){
		component.setBounds(x,y,(int)d.getWidth(),(int)d.getHeight());
		return this;
	}
	public MakeChain<T> addTo(Container parent){
		parent.add(((JComponent)component));
		return this;
	}
	public MakeChain<T> addActionListenerx(ActionListener l){
		((RButton)component).addActionListener(l);
		return this;
	}
	public MakeChain<T> addMouseListenerx(MouseListener l){
		component.addMouseListener(l);
		return this;
	}
	public MakeChain<T> setBackgroundx(Color background){
		component.setBackground(background);
		return this;
	}
	public MakeChain<T> setForegroundx(Color foreground){
		component.setForeground(foreground);
		return this;
	}
	public MakeChain<T> setFontx(Font font){
		component.setFont(font);
		return this;
	}
	public MakeChain<T> setOpaquex(boolean isOpaque){
		component.setOpaque(isOpaque);
		return this;
	}
	public T getObj(){
		return component;
	}
}
